package com.zeta.eduservice.controller.question;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zeta.base.BaseController;
import com.zeta.commonutils.R;
import com.zeta.eduservice.entity.question.EduQuestion;
import com.zeta.eduservice.entity.question.EduQuestionChoice;
import com.zeta.eduservice.entity.vo.QuestionQuery;
import com.zeta.eduservice.entity.vo.QuestionUploadVo;
import com.zeta.eduservice.entity.vo.questionVo;
import com.zeta.eduservice.entity.vo.front.EduQuestionVo;
import com.zeta.eduservice.service.ChapterAQuestionTypeSysAndChoicequestionService;
import com.zeta.eduservice.service.ChapterAQuestionTypeSysAndQuestionService;
import com.zeta.eduservice.service.EduChapterAndQuestionTypeSysService;
import com.zeta.eduservice.service.EduQuestionService;

import io.swagger.annotations.ApiOperation;
import lombok.experimental.PackagePrivate;

/**
 * <p>
 * 试题 前端控制器
 * </p>
 *
 * @author zeta
 * @since 2020-08-25
 */

@CrossOrigin
@RestController
@RequestMapping("/eduservice/edu_question")
public class EduQuestionController extends BaseController<EduQuestion>{
	@Override
	public IService<EduQuestion> getBaseService() {
		// TODO Auto-generated method stub
		return questionService;
	}
	@Autowired
	private EduQuestionService questionService;
	@Autowired
	private EduChapterAndQuestionTypeSysService eduChapterAndQuestionTypeSysService;
	@Autowired
	private ChapterAQuestionTypeSysAndQuestionService chapterAQuestionTypeSysAndquestionService; 
	
	@PostMapping("upload")
	public void addQuestions(MultipartFile file, QuestionUploadVo currChapterId) throws IOException {
		 questionService.upload(file,currChapterId ,questionService,chapterAQuestionTypeSysAndquestionService);

	}
	@PostMapping("/retId")
	public R add(@RequestBody EduQuestion object) {
		boolean save = questionService.save(object);
		if(save)
			return R.ok().data("id",object.getId());
		else 
			return R.error();
		
		
	}


//	@GetMapping("{chapterId}")
//	public R GetQuestions(@PathVariable String chapterId) {
//		QueryWrapper<EduQuestion> queryWrapper=new QueryWrapper<EduQuestion>();
//		queryWrapper.eq("chapter_id", chapterId);
//		List<EduQuestion> listMaps = questionService.list(queryWrapper);
//		return R.ok().data("questions",listMaps);
//	}
	@GetMapping("getsBycourseId/{courseId}")
	public R GetQuestionsByCourseId(@PathVariable String courseId) {
		List<EduQuestion> listMaps = questionService.getsByCourseId(courseId);
		return R.ok().data("questions",listMaps);
	}
	@GetMapping("getsByfolderId/{folderId}")
	public R getQuestionByfolderId(@PathVariable String folderId) {
		List<EduQuestionVo> getsByfolderId = questionService.getsByfolderId(folderId);
		return R.ok().data("questions",getsByfolderId);
	}
	@PostMapping("page/{current}/{limit}")
	public R GetQuestionsByQuestionTypeMidid(@PathVariable long current, @PathVariable long limit,@RequestBody(required = false) QuestionQuery searchObj) {
	
		
		Page<questionVo> page = new Page<>(current, limit);
		List<questionVo> byclass = questionService.getsByMidId(page,searchObj);
		long total = page.getTotal();
		return R.ok().data("total", total).data("list", byclass);

	}
	@PostMapping("pageByPaper/{current}/{limit}")
	public R getByPaperTypeId(@PathVariable long current, @PathVariable long limit,@RequestBody(required = false) QuestionQuery searchObj) {
	
		
		Page<questionVo> page = new Page<>(current, limit);
		List<questionVo> byclass = questionService.getByPaperTypeId(page,searchObj);
		long total = page.getTotal();
		return R.ok().data("total", total).data("list", byclass);

	}
	@PostMapping("pageByTypeAndCourse/{current}/{limit}")
	public R GetChoiceQuestionsByQuestionTypeSys(@PathVariable long current, @PathVariable long limit,@RequestBody(required = false) QuestionQuery searchObj) {
		Page<questionVo> page = new Page<>(current, limit);
		List<questionVo> byclass = questionService.getQuestionsByQuestionTypeSys(page,searchObj);
		long total = page.getTotal();
		return R.ok().data("total", total).data("list", byclass);

	}
	
}

